package net.proef.dozer.listener;

import org.dozer.DozerEventListener;
import org.dozer.event.DozerEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LoggingDozerEventListener implements DozerEventListener {

	private Logger logger = LoggerFactory
			.getLogger(LoggingDozerEventListener.class);

	@Override
	public void mappingStarted(DozerEvent event) {
		logger.trace("Start mapping from {} to {}", event.getClassMap()
				.getSrcClassName(), event.getClassMap().getDestClassName());
	}

	@Override
	public void preWritingDestinationValue(DozerEvent event) {
		logger.trace("Read '{}' from {}.{}", new Object[] {
				event.getFieldMap().getSrcFieldValue(event.getSourceObject()),
				event.getClassMap().getSrcClassName(),
				event.getFieldMap().getSrcFieldName() });
	}

	@Override
	public void postWritingDestinationValue(DozerEvent event) {
		logger.trace(
				"Set {}.{} to '{}'",
				new Object[] { event.getClassMap().getDestClassName(),
						event.getFieldMap().getDestFieldName(),
						event.getDestinationValue() });
	}

	@Override
	public void mappingFinished(DozerEvent event) {
		logger.trace("Mapped from {} to {}", event.getSourceObject(),
				event.getDestinationObject());
	}
}
